/*
 * @Descripttion: 
 * @version: 
 * @Author: 周志伟
 * @Date: 2021-07-05 11:32:07
 * @LastEditors: 周志伟
 * @LastEditTime: 2021-07-07 16:41:06
 */
const { readFileSync } = require('fs');

/** 包名 */
const PACKAGE_NAME = 'zzw_uuid_replace';
Editor.Panel.extend({
  /** HTML */
  template: readFileSync(Editor.url(`packages://${PACKAGE_NAME}/panel/index.html`), 'utf8'),

  /** 样式 */
  style: readFileSync(Editor.url(`packages://${PACKAGE_NAME}/panel/index.css`), 'utf8'),



  // method executed when template and styles are successfully loaded and initialized
  ready() {
    // 创建 Vue 实例
    new window.Vue({

      /**
       * 挂载目标
       * @type {string | Element}
       */
      el: this.shadowRoot,

      /**
       * 数据对象
       */
      data: {
        // 多语言文本
        titleLabel: "uuid--替换",
        uuidLabel1: "脚本 uuid",
        uuidLabel2: "替换脚本 uuid",
        findLabel: "替换",
        backLabel: "撤销",
        // 资源 uuid
        secenesJson: null,
        uuid1: '0ab60320-2418-429c-a32e-9509545196c3',
        uuid2: 'f958dbf8-961d-4e26-b232-95d38f467ba2',
        // 按钮状态
      },

      /**
       * 实例函数
       * @type {{ [key: string]: Function }}
       */
      methods: {

        /**
         * 查找
         */
        onFindBtnClick() {
          // uuid
          const config = {
            oldUuid: this.uuid1,
            newUuid: this.uuid2,
            prefabUuid: this.secenesJson
          }
          Editor.log(config)
          // 发消息给主进程
          Editor.Ipc.sendToMain(`${PACKAGE_NAME}:start-replace-uuid`, config, (error) => {
            Editor.log('onFindBtnClick 发消息给主进程!');
          });
        },
        onbackClick() {
          // 发消息给主进程
          Editor.Ipc.sendToMain(`${PACKAGE_NAME}:back-replace-uuid`, (error) => {
            Editor.log('onFindBtnClick 发消息给主进程!');
          });
        }
      },
    });
  }
});